/**
 * Title :	jFamilyTree generator
 * Description: jFamilyTree generator
 * Version:	provider
 * Copyright (c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.generator;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import jFamilyTree.Messages;

/**
 * Tool bar
 * 
 * @author Bernard Bou
 */
public class Toolbar extends JToolBar
{
	private static final long serialVersionUID = 1L;

	// D A T A

	/**
	 * Controller (command sink)
	 */
	private Controller theController;

	/**
	 * Vertical layout
	 */
	static public final boolean isVertical = true;

	// C O N S T R U C T O R

	/**
	 * Constructor
	 */
	public Toolbar()
	{
		super(isVertical ? VERTICAL : HORIZONTAL);
		setFloatable(true);
		setPreferredSize(new Dimension(36,20+8*36));
		initialize();
	}

	/**
	 * Initialize
	 */
	private void initialize()
	{
		JButton thisOpenButton = makeButton(Messages.getString("Toolbar.10"), Messages.getString("Toolbar.11"), "open.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisOpenButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.OPEN, 0);
			}
		});

		JButton thisOpenHttpButton = makeButton(Messages.getString("Toolbar.20"), Messages.getString("Toolbar.21"), "openurl.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisOpenHttpButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.OPENURL, 0);
			}
		});

		JButton thisNewButton = makeButton(Messages.getString("Toolbar.30"), Messages.getString("Toolbar.31"), "newdoc.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisNewButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.NEW, 0);
			}
		});

		JButton thisSaveButton = makeButton(Messages.getString("Toolbar.40"), Messages.getString("Toolbar.41"), "save.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisSaveButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.SAVE, 0);
			}
		});

		JButton thisMakeSiteButton = makeButton(Messages.getString("Toolbar.50"), Messages.getString("Toolbar.51"), "sitemake.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisMakeSiteButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.MAKESITE, 0);
			}
		});

		JButton thisRunSiteButton = makeButton(Messages.getString("Toolbar.60"), Messages.getString("Toolbar.61"), "siterun.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisRunSiteButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.RUNSITE, 0);
			}
		});

		JButton thisHelpButton = makeButton(Messages.getString("Toolbar.70"), Messages.getString("Toolbar.71"), "help.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisHelpButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.HELP, 0);
			}
		});

		JButton thisUpdateNodeButton = makeButton(Messages.getString("Toolbar.80"), Messages.getString("Toolbar.81"), "refresh.png"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		thisUpdateNodeButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				theController.execute(Controller.Code.UPDATE, 0);
			}
		});

		this.add(thisOpenButton);
		this.add(thisOpenHttpButton);
		this.add(thisNewButton);
		this.add(thisSaveButton);
		this.add(thisUpdateNodeButton);
		this.add(thisMakeSiteButton);
		this.add(thisRunSiteButton);
		this.add(thisHelpButton);
	}

	/**
	 * Make theButton
	 * 
	 * @param thisText
	 *        text
	 * @param thisTooltip
	 *        tooltip
	 * @param thisImage
	 *        image
	 * @return theButton
	 */
	private JButton makeButton(String thisText, String thisTooltip, String thisImage)
	{
		JButton thisButton = new JButton();
		thisButton.setToolTipText(thisTooltip);
		thisButton.setIcon(new ImageIcon(Toolbar.class.getResource("images/" + thisImage))); //$NON-NLS-1$
		return thisButton;
	}

	/**
	 * Set controller
	 * 
	 * @param thisController
	 *        controller
	 */
	public void setController(Controller thisController)
	{
		theController = thisController;
	}
}
